package com.weixin.model;

import java.util.Date;
import java.util.UUID;

import com.gesonet.pay.utils.DateUtils;
import com.gesonet.pay.utils.PayCommonUtil;
import com.weixin.WechatConfig;

public class WxPrePayReq {
	
	
	public static final String TRADE_TYPE_APP = "APP";
	public static final String TRADE_TYPE_JSAPI = "JSAPI";
	
	/**微信分配的公众账号ID（企业号corpid即为此appId）*/
	private String appid = WechatConfig.APPID;
	
	/**附加数据，在查询API和支付通知中原样返回，该字段主要用于商户携带订单的自定义数据*/
	private String attach;
	
	/**商品简单描述，该字段须严格按照规范传递，
	 * 具体请见参数规定https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_2*/
	private String body;
	
	/**商品详细列表，使用Json格式，传输签名前请务必使用CDATA标签将JSON文本串保护起来。*/
	private String detail;
	
	/**终端设备号(门店号或收银设备ID)，
	 * 注意：PC网页或公众号内支付请传"WEB"*/
	private String device_info;
	
	/**符合ISO 4217标准的三位字母代码，默认人民币：CNY，
	 * 其他值列表详见货币类型https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_2*/
	private String fee_type = "CNY";
	
	/**商品标记，代金券或立减优惠功能的参数，
	 * 说明详见代金券或立减优惠https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_1*/
	private String goods_tag;
	
	/**no_credit--指定不能使用信用卡支付*/
	private String limit_pay;
	
	/**微信支付分配的商户号*/
	private String mch_id = WechatConfig.MCH_ID;
	
	/**随机字符串，不长于32位。
	 * 推荐随机数生成算法https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3*/
	private String nonce_str = UUID.randomUUID().toString().toUpperCase().replaceAll("-", "");
	
	/**接收微信支付异步通知回调地址，通知url必须为直接可访问的url，不能携带参数。*/
	private String notify_url = WechatConfig.NOTIFY_URL;
	
	/**trade_type=JSAPI，此参数必传，用户在商户appid下的唯一标识。
	 * openid如何获取，可参考【获取openid】https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_4。
	 * 企业号请使用【企业号OAuth2.0接口】获取企业号内成员userid，
	 * http://qydev.weixin.qq.com/wiki/index.php?title=OAuth%E9%AA%8C%E8%AF%81%E6%8E%A5%E5%8F%A3
	 * 再调用【企业号userid转openid接口】进行转换
	 * http://qydev.weixin.qq.com/wiki/index.php?title=Userid%E4%B8%8Eopenid%E4%BA%92%E6%8D%A2%E6%8E%A5%E5%8F%A3*/
	private String openid;
	
	/**商户系统内部的订单号,32个字符内、可包含字母, 
	 * 其他说明见商户订单号https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_2*/
	private String out_trade_no = PayCommonUtil.createTradeOrderNo(6);
	
	/**trade_type=NATIVE，此参数必传。此id为二维码中包含的商品ID，商户自行定义。*/
	private String product_id;
	
	/**签名，详见签名生成算法
	 * https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3*/
	private String sign;
	
	/**APP和网页支付提交用户端ip，Native支付填调用微信支付API的机器IP。*/
	private String spbill_create_ip;
	
	/**订单总金额，单位为分，详见支付金额https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_2*/
	private int total_fee;
	
	/**订单失效时间，格式为yyyyMMddHHmmss，如2009年12月27日9点10分10秒表示为20091227091010。
	 * 其他详见时间规则https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_2
	 * 注意：最短失效时间间隔必须大于5分钟*/
	private String time_expire;
	
	/**订单生成时间，格式为yyyyMMddHHmmss，
	 * 如2009年12月25日9点10分10秒表示为20091225091010。
	 * 其他详见时间规则https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_2*/
	private String time_start = DateUtils.format(new Date(),DateUtils.FORMAT_YMDHMS);
	
	/**取值如下：JSAPI，NATIVE，APP，
	 * 详细说明见参数规定https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_2*/
	private String trade_type = TRADE_TYPE_JSAPI;
	
	public WxPrePayReq(String appid, String attach, String body, String detail, String device_info, String fee_type,
			String goods_tag, String limit_pay, String mch_id, String nonce_str, String notify_url, String openid,
			String out_trade_no, String product_id, String sign, String spbill_create_ip, int total_fee,
			String time_expire, String time_start, String trade_type) {
		super();
		this.appid = appid;
		this.attach = attach;
		this.body = body;
		this.detail = detail;
		this.device_info = device_info;
		this.fee_type = fee_type;
		this.goods_tag = goods_tag;
		this.limit_pay = limit_pay;
		this.mch_id = mch_id;
		this.nonce_str = nonce_str;
		this.notify_url = notify_url;
		this.openid = openid;
		this.out_trade_no = out_trade_no;
		this.product_id = product_id;
		this.sign = sign;
		this.spbill_create_ip = spbill_create_ip;
		this.total_fee = total_fee;
		this.time_expire = time_expire;
		this.time_start = time_start;
		this.trade_type = trade_type;
	}
	
	
	/**
	 * 统一下单必填参数（trade_type=JSAPI时，openid必填）
	 * @param appid
	 * @param body
	 * @param mch_id
	 * @param nonce_str
	 * @param notify_url
	 * @param openid
	 * @param out_trade_no
	 * @param sign
	 * @param spbill_create_ip
	 * @param total_fee
	 * @param trade_type
	 */
	public WxPrePayReq(String appid, String body, String mch_id, String nonce_str, String notify_url, String openid,
			String out_trade_no, String sign, String spbill_create_ip, int total_fee, String trade_type) {
		super();
		this.appid = appid;
		this.mch_id = mch_id;
		this.notify_url = notify_url;
		this.nonce_str = nonce_str;
		this.body = body;
		this.openid = openid;
		this.out_trade_no = out_trade_no;
		this.sign = sign;
		this.spbill_create_ip = spbill_create_ip;
		this.total_fee = total_fee;
		this.trade_type = trade_type;
	}

	public WxPrePayReq(String body, int total_fee,
			String spbill_create_ip, String trade_type) {
		super();
		this.body = body;
		this.total_fee = total_fee;
		this.spbill_create_ip = spbill_create_ip;
		this.trade_type = trade_type;
	}
	
	/**
	 * 除读取配置外的动态数据
	 * @param body
	 * @param total_fee
	 * @param openid
	 * @param spbill_create_ip
	 * @param trade_type
	 */
	public WxPrePayReq(String body, String openid,int total_fee,String spbill_create_ip) {
		super();
		this.body = body;
		this.total_fee = total_fee;
		this.openid = openid;
		this.spbill_create_ip = spbill_create_ip;
	}

	public WxPrePayReq() {
		super();
	}

	public String getAppid() {
		return appid;
	}

	public void setAppid(String appId) {
		this.appid = appId;
	}

	public String getMch_id() {
		return mch_id;
	}

	public void setMch_id(String mch_id) {
		this.mch_id = mch_id;
	}

	public String getDevice_info() {
		return device_info;
	}

	public void setDevice_info(String device_info) {
		this.device_info = device_info;
	}

	public String getNonce_str() {
		return nonce_str;
	}

	public void setNonce_str(String nonce_str) {
		this.nonce_str = nonce_str;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	public String getDetail() {
		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	public String getAttach() {
		return attach;
	}

	public void setAttach(String attach) {
		this.attach = attach;
	}

	public String getOut_trade_no() {
		return out_trade_no;
	}

	public void setOut_trade_no(String out_trade_no) {
		this.out_trade_no = out_trade_no;
	}

	public String getFee_type() {
		return fee_type;
	}

	public void setFee_type(String fee_type) {
		this.fee_type = fee_type;
	}

	public int getTotal_fee() {
		return total_fee;
	}

	public void setTotal_fee(int total_fee) {
		this.total_fee = total_fee;
	}

	public String getSpbill_create_ip() {
		return spbill_create_ip;
	}

	public void setSpbill_create_ip(String spbill_create_ip) {
		this.spbill_create_ip = spbill_create_ip;
	}

	public String getTime_start() {
		return time_start;
	}

	public void setTime_start(String time_start) {
		this.time_start = time_start;
	}

	public String getTime_expire() {
		return time_expire;
	}

	public void setTime_expire(String time_expire) {
		this.time_expire = time_expire;
	}

	public String getGoods_tag() {
		return goods_tag;
	}

	public void setGoods_tag(String goods_tag) {
		this.goods_tag = goods_tag;
	}

	public String getNotify_url() {
		return notify_url;
	}

	public void setNotify_url(String notify_url) {
		this.notify_url = notify_url;
	}

	public String getTrade_type() {
		return trade_type;
	}

	public void setTrade_type(String trade_type) {
		this.trade_type = trade_type;
	}

	public String getLimit_pay() {
		return limit_pay;
	}

	public void setLimit_pay(String limit_pay) {
		this.limit_pay = limit_pay;
	}

	public String getProduct_id() {
		return product_id;
	}

	public void setProduct_id(String product_id) {
		this.product_id = product_id;
	}

	public String getOpenid() {
		return openid;
	}

	public void setOpenid(String openid) {
		this.openid = openid;
	}
	
}
